/*修改按钮*/
let change = document.getElementsByClassName("change");
/*删除按钮*/
let deleteUser = document.getElementsByClassName("delete");
/*弹窗*/
let popupWindow = document.getElementsByClassName("popupWindow");
let userNameS = document.getElementsByClassName("userNameS");
/*点击删除*/
var allTd = document.getElementsByClassName("td");
for (let i = 0; i < deleteUser.length; i++) {
    /*点击修改或删除按钮弹出弹窗*/
    deleteUser[i].onclick = function () {
        mask.style.display = "block";
        popupWindow[i].style.display = "block";
        userNameS[i].innerHTML = allTd[i * 11 + 2].innerHTML;
    }
}

//返回顶部
function Tips(i) {
    let tip = document.getElementsByClassName("tips")[0];
    tip.innerHTML = i;
    tip.style.top = "56px";
    let timer = setTimeout(function () {
        tip.style.top = "-56px";
        clearTimeout(timer);
    }, 1000);
}

/*取消按钮*/
let cancel = document.getElementsByClassName("cancel");
/*确定按钮*/
let determine = document.getElementsByClassName("determine");

/*点击确定或取消按钮弹窗消失*/
for (let i = 0; i < cancel.length; i++) {
    cancel[i].onclick = function () {
        mask.style.display = "none";
        popupWindow[i].style.display = "none";
    }
}
for (let i = 0; i < determine.length; i++) {
    determine[i].onclick = function () {
        mask.style.display = "none";
        popupWindow[i].style.display = "none";
    }
}
let popInput = document.getElementsByClassName("popInput");
for (let i = 0; i < 8; i++) {
    popInput[i].onfocus = function () {
        popInput[i].style.border = "1px solid #89c3eb";
    }
    popInput[i].onblur = function () {
        popInput[i].style.border = "1px solid rgba(0,0,0,0.1)"
    }
}
let cut = document.getElementsByClassName("cut");
// let deleteBtn=document.getElementById("deleteBtn");
var mask = document.getElementsByClassName("mask")[0];
let pop = document.getElementsByClassName("pop");
let userNoBtn = document.getElementById("userNoBtn");
let userYesBtn = document.getElementById("userYesBtn");
let tbody = document.getElementsByClassName("tbody")[0];
let optionWomen = document.getElementsByClassName("optionWomen");
let optionMen = document.getElementsByClassName("optionMen");
let option = document.getElementById("option");
for (let i = 0; i < change.length; i++) {
    change[i].onclick = function () {
        mask.style.display = "block";
        pop[i].style.display = "block";
    }
    cut[i].onclick = function () {
        mask.style.display = "none";
        pop[i].style.display = "none";
    }
    userNoBtn.onclick = function () {
        mask.style.display = "none";
        pop[i].style.display = "none";
    }
    userYesBtn.onclick = function () {
        mask.style.display = "none";
        pop[i].style.display = "none";
    }
}

let examine = document.getElementsByClassName("examine");
let examinePop = document.getElementsByClassName("examinePop");
let examineCut = document.getElementsByClassName("examineCut");
for (let i = 0; i < examine.length; i++) {
    examine[i].onclick = function () {
        mask.style.display = "block";
        examinePop[i].style.display = "block";
        // for(let j=0;j<allTd.length;j++){
        //     popInput[j].value=allTd[j].innerHTML;
        // }
    }
    examineCut[i].onclick = function () {
        mask.style.display = "none";
        examinePop[i].style.display = "none";
    }
}

//搜索用户
let selectBtn = document.getElementById("selectBtn");
selectBtn.onclick = function () {
    $.ajax({})
}

//批量删除
let batchDelete = document.getElementsByClassName("batchDelete")[0];
let successDelete = document.getElementsByClassName("successDelete")[0];
// let tbody=document.getElementsByClassName("tbody");
let allTr = tbody.getElementsByTagName("tr");
batchDelete.onclick = function () {
    let userTable = document.getElementById("userTable");
    let allTh = userTable.getElementsByTagName("th");
    allTh[0].style.display = "block";
    successDelete.style.display = "block";
    for (let j = 0; j < allTr.length; j++) {
        allTd[j * 11].style.display = "block";
        allTd[j * 11].style.border = "0";
        // console.log(allTr(j*11+1))
    }
}
//批量删除
successDelete.onclick = function () {
    //获取选中的复选框
    let checkBox = document.getElementsByClassName("checkBox");
    var arr = [];
    for (let i = 0; i < allTr.length; i++) {
        if (checkBox[i].checked == true) {
            arr.push(allTd[i * 11 + 1].innerHTML);
            console.log(allTd[i * 11 + 1].innerHTML)
        }
    }
    var b=" ";
    for (let i in arr){
        b+=arr[i]
        if(i==arr.length-1){
            break
        }
        b+='%2C'
    }
    if(arr.length==0){
        alert("您还未选择需进行删除的用户")
    }else{
        var Confirm = confirm("确定删除这些用户吗");
        if (Confirm == true) {
            $.ajax({
                url: "../manager/deleteList?idArr=" + b,
                type: "delete",
                // data:{
                //     ids:10,
                //     // ids:JSON.stringify(arr).replace(/[\[\]]/g,''),
                // },
                success: function (data) {
                    if (data.msg == "删除成功") {
                        alert("删除成功");
                        window.location.reload();
                    } else {
                        console.log(data)
                    }
                }
            })
        } else {

        }
    }

}
//重置刷新恢复默认状态
let resetting = document.getElementsByClassName("resetting")[0];
resetting.onclick = function () {
    window.location.reload();
}





